package top.kaoshanji.r2ch07d;

import org.springframework.aop.BeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;

/**
 * 代码清单-r2ch07d-232页d：使用前置增强
 * @author kaoshanji
 * ^_^
 * create time 2025/5/7 16:54
 */
public class GreetingBeforeAdviceMain {

    public static void main(String[] args) {

        // 目标对象
        Waiter target = new NaiveWaiter();
        // 前置增强
        BeforeAdvice advice = new GreetingBeforeAdvice();

        // Spring提供的代理工厂
        ProxyFactory proxyFactory = new ProxyFactory();
        // 设置代理目标
        proxyFactory.setTarget(target);
        // 为代理目标添加增强
        proxyFactory.addAdvice(advice);

        // 获取生成代理实例：包含原来的逻辑和增强的逻辑
        Waiter proxy = (Waiter) proxyFactory.getProxy();

        proxy.greetTo("John");
        proxy.serveTo("Tom");

    }

}
